<?php
/*
*
* @author ram
*
*/
require_once("config.php");
require_once("header.php");

$allow_url_fopen = ini_get('allow_url_fopen');
if (!$allow_url_fopen) {
	ini_set('allow_url_fopen', 1);
}

$allow_url_fopen = ini_get('allow_url_fopen');
if (!$allow_url_fopen && !FSOCK_ENABLED ) {
	echo '<span class="error"><b>Note</b>: Please enable \'<em>allow_url_fopen</em>\' option in PHP configuration file</span><br/>';
}

$search_url = trim(@$_POST['search_url']);
$search_page = trim(@$_POST['search_page']);

if (empty($search_url) ) {
	header("Location: index.php");
	exit;
}
?>
<script src="javascript.js"></script>
<script>

var TotalLinks = 1;

var myLinks = ['','<?php echo addslashes($search_url); ?>'];

function do_getlinks(ob) {
	
	if(ob.responseText != '') {
		try{
			display_text(ob.responseText);
		} catch(e) {
		}
	}
	
	TotalLinks++;
	
	if (TotalLinks < myLinks.length ) {
	
		start_get_links(TotalLinks);
		
	} else {
	
		document.getElementById('progress_table').innerHTML = '';
		exit_search();
	}
	
}

function start_get_links(n) {

	document.getElementById('progress_table').innerHTML = 'Processing....<b>'+myLinks[n]+'</b>';

	xmlhttp_config = {"URL":"get_page.php","METHOD":"POST","ASYNCH":true};
	
	xmlHRH = new xmlHttpRequestHandler(xmlhttp_config);
	
	xmlHRH.setData("fxid="+encodeURI(myLinks[n])+"&num="+n);
	
	xmlHRH.send(do_getlinks);
	
}

function display_text(response_text) {

	//alert(response_text);
	
	try { var links_avail = eval(response_text); }  catch(e) { var links_avail = new Array(); }
	
	//alert(links_avail.length+typeof(links_avail));
	
	if (typeof(links_avail) != 'undefined') {
		
		var k = 0; 
		
		//alert(response_text);
		
		for(var i=0; i<links_avail.length; i++) {
		
			//alert(links_avail.length+': '+links_avail[i]);
			
			if ( in_list(links_avail[i], myLinks) == false) {
			
				myLinks[myLinks.length] = links_avail[i];
				var cls = '';
				
				//alert(myLinks.length);
				
				if (k % 2 == 0) cls = '#E5E5E5'; else cls = '#F8F8F8';
				
				k++;
				add_url_ro_table(links_avail[i], cls);
			}
		}
		//for LOOP ENDS here
	}
}

function in_list(key, list) {
	var f = false;
	
	for(var incr=0; incr<list.length; incr++) {
	
		if (list[incr] == key) {
			f = true;
			break;
		}
	}
	return f;
}
</script>
<table width="98%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td class="bodytext"><div id="progress_table">Processing....</div>
	<br />
	<div id="txt">Time elapsed: 0:00 Mins</div>
	<script>
		startTime();
		start_get_links(1);
	</script>
	</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
<br />
<table width="98%" border="0" cellspacing="1" cellpadding="0" class="mytable">
<tbody id="tbody2">
  <tr class="headingbar">
    <td width="59%" height="35" align="center" valign="middle"><strong>URL</strong></td>
    <td width="41%" align="center" valign="middle"><strong>Rank</strong></td>
  </tr>
  <tr class="tr2">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</tbody>
</table>

<?php
require_once("footer.php");
?>